//
// Created by luo on 2022-10-17.
//

//10.18

#ifndef ARMOR_DETECT_SERIAL_H
#define ARMOR_DETECT_SERIAL_H

#ifndef DIANSAI_SERIAL_H
#define DIANSAI_SERIAL_H

#ifndef UINT
typedef unsigned int UINT;
#endif

#ifndef UCHAR
typedef unsigned char UCHAR;
#endif

#include <vector>
#include <iostream>
using namespace std;

/**
* @brief: CLinuxSerial class　实现串口通信
*/

extern int Hordistance;

struct Visual_Receive//视觉接收管理
{
    uint16_t yaw;
    uint16_t pitch;
    uint16_t speed;
    uint mode;
    uint8_t color;
};

struct Visual_Send//视觉发送管理
{
    uint16_t yaw;
    uint16_t pitch;
    uint mode;  // 0 aim 1 buff 2 shaobing
    uint16_t Distance;
    uint8_t F_time;
};

class CLinuxSerial
{
public:
    CLinuxSerial();
    ~CLinuxSerial();

    bool InitPort(UINT portNo = 0, UINT baudRate = 115200);
    void ReadData(uint8_t *data, UINT length);
    void WriteData(uint8_t *data, UINT length);
    UINT GetBytesInCom();
    int getfd2car();

    void send_YP(int yaw, int pitch, unsigned int sort_num, unsigned int baud_rate,unsigned int Hordistance);
    vector<int> receive_data(unsigned int sort_num, unsigned int baud_rate);
    bool OpenPort(UINT portNo);
    void ClosePort();

private:
    int m_iSerialID;

};

#endif

#endif //ARMOR_DETECT_SERIAL_H
